<template>
    <div class="mainDiv">
        <el-row :gutter="20" class="rowHead">
            <el-col :span="12">
                <el-button type="success" icon="el-icon-plus" @click="addsubject" v-qx="quanxian.pull">拉取项目</el-button>
                <el-select v-model="page.zt" @change="getList" class="ml" v-qx="quanxian.status">
                    <el-option v-for="o in leaves" :label="o.txt" :value="o.val"></el-option>
                </el-select>
            </el-col>
            <el-col :span="9">
                <el-input @keyup.enter.native="getList" placeholder="搜索项目名称、编号" v-model="page.search">
                    <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="getList"></i>
                </el-input>
            </el-col>
            <el-col :span="3">
                <el-button type="primary" icon="el-icon-h-shuaxin1" style="float:right" @click="refresh">刷新列表</el-button>
            </el-col>
        </el-row>
        <el-table :data="slist" :stripe="true" height="100%">
            <el-table-column type="index" :index="sIndex" label="#"></el-table-column>
            <el-table-column prop="name" label="项目名称"></el-table-column>
            <el-table-column prop="number" label="项目编号"></el-table-column>
            <el-table-column prop="usetime" label="项目用时">
                <template slot-scope="scope">
                    {{scope.row.usetime+'分钟'}}
                </template>
            </el-table-column>
            <el-table-column prop="price" label="项目价格">
                <template slot-scope="scope">
                    {{scope.row.price+'元'}}
                </template>
            </el-table-column>
            <el-table-column prop="xstdtype" label="销售提成">
                <template slot-scope="scope">
                    <el-tag color="#fdffdd" v-if="scope.row.xstdtype==1" size="mini">{{Number(scope.row.xspercent*100).toFixed(0)+'%'}}</el-tag>
                    <el-tag color="#f5feff" v-else size="mini">{{scope.row.xsfixed+'元'}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="sgtdtype" label="手工提成">
                <template slot-scope="scope">
                    <el-tag color="#fdffdd" v-if="scope.row.sgtdtype==1" size="mini">{{Number(scope.row.sgpercent*100).toFixed(0)+'%'}}</el-tag>
                    <el-tag color="#f5feff" v-else size="mini">{{scope.row.sgfixed+'元'}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="khtdtype" label="卡耗提成">
                <template slot-scope="scope">
                    <el-tag color="#fdffdd" v-if="scope.row.khtdtype==1" size="mini">{{Number(scope.row.khpercent*100).toFixed(0)+'%'}}</el-tag>
                    <el-tag color="#f5feff" v-else size="mini">{{scope.row.khfixed+'元'}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="bname" label="所属品牌"></el-table-column>
            <el-table-column prop="cname" label="所属分类"></el-table-column>
            <el-table-column prop="remarks" label="项目描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="sisdisable" label="机构状态">
                <template slot-scope="scope">
                    <el-tag :type="scope.row.sisdisable?'danger':'primary'" size="mini">
                        {{scope.row.sisdisable?'弃用':'正常'}}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="120">
                <template slot-scope="scope">
                    <el-button-group v-if="!scope.row.isdisable">
                        <el-button type="warning" icon="el-icon-edit" size="mini" @click="edit(scope.row)" v-qx="quanxian.edit"></el-button>
                        <el-tooltip content="停用" placement="top" v-qx="quanxian.unstop">
                            <el-button icon="el-icon-h-jinyong" type="danger" size="mini" @click="unstop(scope.row.id,1)"></el-button>
                        </el-tooltip>
                    </el-button-group>
                    <el-tooltip content="启用" placement="top" v-else v-qx="quanxian.unstop">
                        <el-button icon="el-icon-h-qiyong2" type="success" size="mini" @click="unstop(scope.row.id,0)"></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>
        <div style="margin-top: 14px;">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="page.pages" :page-sizes="[15, 30, 50, 100]" :page-size="page.limits" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import C from '#/src/common/common.js'
import Subject from '#/src/shop/subject.js'
export default {
    name: 'subjectList',
    data() {
        return {
            slist: [],
            total: 0,
            page: {
                pages: 1,
                limits: 15,
                search: '',
                zt: 0,
            },
            leaves: [{
                txt: '正常',
                val: 0
            }, {
                txt: '停用',
                val: 1
            }],
            quanxian: {
                pull: 'project_pull',
                unstop: 'project_unstop',
                status: 'project_status',
                edit: 'project_edit'
            }
        }
    },
    methods: {
        addsubject: async function() {
            let res = await C.openBrowserWindow('/pullSubject', {}, { width: 1400, height: 800, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
            if (res) {
                C.success(res)
                this.getList()
            }
        },
        edit: async function(row) {
            // 编辑
            let res = await Subject.openEditSubject(row)
            if (res && res.data) {
                C.success(res.data)
                this.getList()
            }
        },
        // 启用、弃用
        unstop: async function(id, status) {
            let str = ''
            if (status) str = '确定停用当前项目？'
            else str = '启用当前项目？'
            C.confirm(str, async() => {
                let res = await C.ajax('/shop/subject/unstop', { id: id, status: status }, 'post')
                if (res) {
                    C.success(res.data)
                    this.getList()
                }
            })
        },
        refresh: function() {
            this.getList()
        },
        sizeChange: function(val) {
            this.page.limits = val
            this.getList()
        },
        currentChange: function(val) {
            this.page.pages = val
            this.getList()
        },
        sIndex(index) {
            return (this.page.pages - 1) * this.page.limits + index + 1
        },
        getList: async function() {
            let data = await C.ajax('/shop/subject/subjectlist', this.page, 'post')
            if (data) {
                this.slist = data.data
                this.total = data.count
            }
        }
    },
    mounted: function() {
        this.getList()
    }
}
</script>